using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SceneLoader : MonoBehaviour
{
    [SerializeField] private GameObject floor;

    // 摄像机的四个角的坐标。
    private float xMin, xMax, yMin, yMax;

    void Start()
    {
        // 得到游戏场景的四个角的坐标。
        Camera cam = Camera.main;
        xMin = cam.ViewportToWorldPoint(new Vector3(0, 0, 0)).x + 1;
        xMax = cam.ViewportToWorldPoint(new Vector3(1, 0, 0)).x - 1;
        yMin = cam.ViewportToWorldPoint(new Vector3(0, 0, 0)).y + 1;
        yMax = cam.ViewportToWorldPoint(new Vector3(0, 1, 0)).y - 1;
        for (int i = Mathf.FloorToInt(yMin); i < Mathf.FloorToInt(yMax); i++)
        {
            var item1 = Instantiate(floor, new Vector3(xMin, i, 0), Quaternion.identity);
            item1.transform.parent = transform;
            var item2 = Instantiate(floor, new Vector3(xMax, i, 0), Quaternion.identity);
            item2.transform.parent = transform;
        }
        for (int i = Mathf.FloorToInt(xMin) + 1; i < Mathf.FloorToInt(xMax) + 1; i++)
        {
            var item1 = Instantiate(floor, new Vector3(i, yMin, 0), Quaternion.identity);
            item1.transform.parent = transform;
            var item2 = Instantiate(floor, new Vector3(i, yMax - 1, 0), Quaternion.identity);
            item2.transform.parent = transform;
        }
    }
}
